package bairui.international.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import bairui.international.model.domain.jpa.TB_City;
import bairui.international.model.domain.jpa.TB_Province;
import bairui.international.model.domain.jpa.TB_ProxyAreaAddress;
import bairui.international.model.domain.jpa.TB_Town;
import bairui.international.model.domain.jpa.TB_User;
import bairui.international.model.domain.jpa.id.ID_ProxyAreaAddress;
import bairui.international.service.Service_ProxyAreaAddress;
import bairui.international.service.Service_Town;

/**
 * 
 * 【(代理区域地址)TB_ProxyAreaAddress】服务实现
 *
 * @generated
 * 
 * @see bairui.international.model.domain.jpa.TB_ProxyAreaAddress 模型
 * @see Service_ProxyAreaAddress 服务接口
 * @see BService_ProxyAreaAddressImpl 服务实现基础
 *
 */
@Service
public class Service_ProxyAreaAddressImpl extends BService_ProxyAreaAddressImpl implements Service_ProxyAreaAddress {

	@Autowired private Service_Town service_Town;
	
	@Override
	public TB_ProxyAreaAddress createInstance(TB_User user, TB_Town _town, String username, String phone, String address) {
		TB_Town town = service_Town.load(_town);
		TB_City city = town.getCity();
		TB_Province province = city.getProvince();
		//
		return dao.save(new TB_ProxyAreaAddress(
				new TB_ProxyAreaAddress.MustProperties() {
					@Override public String getUsername() {
						return username;
					}
					@Override public String getPhone() {
						return phone;
					}
					@Override public ID_ProxyAreaAddress getId() {
						return new ID_ProxyAreaAddress(user, town);
					}
					
					@Override public String getFixAddress() {
						return province.getName() + "/" + city.getName() + "/" + town.getName();
					}
					
					@Override
					public String getAddress() {
						return address;
					}
				}, 
				new TB_ProxyAreaAddress.OptionalSingleProperties() {
				}
			));
	}

	@Override
	public void editAddress(TB_User user, Long townId, String username, String phone, String address) {
		TB_ProxyAreaAddress bean = findById(new ID_ProxyAreaAddress(user, new TB_Town(townId)));
			bean.setUsername(username);
			bean.setPhone(phone);
			bean.setAddress(address);
	}
	
}
